package com.example.boot.factorycase;

import com.google.common.collect.Maps;
import org.springframework.stereotype.Component;

import java.util.Map;
import java.util.Optional;

@Component
public class PreCheckScoreCollectorFactory  {

    private static final Map<String, AbstractPreCheckScoreCollector> collectorMap = Maps.newHashMap();

    public static AbstractPreCheckScoreCollector getCollector(String type) {
        return Optional.ofNullable(collectorMap.get(type))
                .orElseThrow(() -> new IllegalArgumentException("Unknown collector type: " + type));
    }

    public static void addCollector(String type, AbstractPreCheckScoreCollector collector) {
        collectorMap.put(type, collector);
    }

}
